/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tpdisenio2009.model.dao;

import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import tpdisenio2009.model.HibernateUtils;
import tpdisenio2009.model.beans.City;
import tpdisenio2009.model.beans.State;

/**
 *
 * @author DeuterioX
 */
public class CityDAO extends AbstractDAO<City> {

    @Override
    public Class<City> getPersistentClass() {
        return City.class;
    }

    public List<City> getByState ( State state ) {
        Session session = HibernateUtils.getCurrentSession();

        Criteria mainCriteria = session.createCriteria( City.class );
        mainCriteria.add( Restrictions.eq( "state", state ) );
        mainCriteria.addOrder( Order.asc( "name" ) );

        return mainCriteria.list();
    }

}
